package domain.lexicalAnalyzerGenerator;

import java.util.List;

import domain.regularExpression.UnaryRegularExpressionOperator;

public class StartsWithInstruction extends Instruction {
	private String possibleTokens;
	private List<Instruction> subInstructions;
	
	public StartsWithInstruction(UnaryRegularExpressionOperator unaryRegularExpressionOperator) 
	throws InstructionException{
		possibleTokens = Instruction.getFirsts(unaryRegularExpressionOperator);
		subInstructions = Instruction.getSubInstructions(unaryRegularExpressionOperator);
	}
	
	public String generateCode() throws CodeGenerationException {
		String res = " if(grammarStringHelper.belongsCurrentToken(\"" + possibleTokens + "\")){\n";
		
		for (int i = 0; i < subInstructions.size(); i++){
			res += subInstructions.get(i).generateCode();
		}
		
		res += "}\n";
		
		return res;
	}

}
